/* eslint-disable react-native/no-inline-styles */
import React from 'react';
import {StyleSheet, View, Pressable, Text} from 'react-native';

interface IProps {
  value: string;
  options: Array<Record<'label' | 'value', string>>;
  onChange: (val: string) => void;
}

function RadioButtonGroup(props: IProps): JSX.Element {
  const value = props.value;
  const options = props.options;
  const onChange = props.onChange;

  return (
    <View style={styles.radioContainer}>
      {options.map(item => (
        <Pressable
          key={item.value}
          onPress={() => {
            onChange(item.value);
          }}>
          <View
            style={{
              ...styles.radioButton,
              backgroundColor:
                value === item.value ? 'rgb(33, 150, 243)' : '#fff',
            }}>
            <Text
              style={{
                color: item.value === value ? '#fff' : 'rgb(33, 150, 243)',
              }}>
              {item.label}
            </Text>
          </View>
        </Pressable>
      ))}
    </View>
  );
}

const styles = StyleSheet.create({
  radioContainer: {
    display: 'flex',
    flexDirection: 'row',
    alignItems: 'center',
  },
  radioButton: {
    borderRadius: 4,
    padding: 4,
    paddingLeft: 8,
    paddingRight: 8,
  },
});

export default RadioButtonGroup;
